#@layout()
#define css()
<link rel="stylesheet" type="text/css" href="#(ctx)/css/jsmind.css" media="all">
#end

#define main()

<div class="container-fluid">
    <!--[if IE]>
    <div class="alert-warning">本系统不能在IE下运行</div>
    <![endif]-->
    <div id="container" class="row"></div>
</div>
#end

#define script()
<script type="text/javascript" src="#(ctx)/js/jsmind.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        const dom = document.getElementById('container');
        let _resize_timeout_id = -1;
        const myChart = new jsMind({
            container: 'container',
            editable: false,
            theme: 'primary',
            default_event_handle: {
                enable_dblclick_handle: false
            }
        });
        const render = {
            showChart: function() {
                render.set_container_size();
                jsMind.util.dom.add_event(window, 'resize', render.reset_container_size);
                
                utils.ajaxPost({
                    url: "#(ctx)/map/chart",
                    done: function(data) {
                        myChart.show(data)
                    }
                });
            },
            set_container_size: function() {
                const cw = window.innerWidth;
                dom.style.width = cw + "px";
            },
            reset_container_size: function() {
                if (_resize_timeout_id != -1) {
                    clearTimeout(_resize_timeout_id);
                }
                _resize_timeout_id = setTimeout(function() {
                    _resize_timeout_id = -1;
                    render.set_container_size();
                    myChart.resize();
                }, 300);
            }
        };
        
        render.showChart();
        $('#container').on('click', 'jmnode', function() {
            const selectedNode = myChart.get_selected_node();
            if (!!selectedNode && !!selectedNode.data) {
                if (selectedNode.data.type == 1 && !!selectedNode.data.path) {
                    let url = "#(uploadUrl)/";
                    if (url.toLowerCase().indexOf("http:") != 0 && url.toLowerCase().indexOf("https:") != 0) {
                        url = "#(ctx)" + url;
                    }
                    const win = window.open(url + selectedNode.data.path);
                    if (!win) {
                        location.href = url + selectedNode.data.path;
                    }
                }
            }
        });
    });
</script>
#end
